package com.chushouya.controller.open;

import com.chushouya.common.annotations.AuthSkip;
import com.chushouya.common.constant.ServiceType;
import com.general.framework.core.schema.Response;
import com.chushouya.order.dto.api.push.OrderPushRequestDTO;
import com.chushouya.order.service.api.OrderPushApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 速回收推送网关
 */
@RestController
@RequestMapping(ServiceType.OPENAPI + "/suhuishouPush")
@Slf4j
public class SuhuishouPushController {

    @Resource
    private OrderPushApiService orderPushApiService;

    @PostMapping("/callback")
    @AuthSkip
    public Response suhuishouNotifyCallBack(@RequestBody OrderPushRequestDTO orderPushRequestDTO) {
        log.info("速回收推送网关接收到回调: {}", orderPushRequestDTO);
        try {
            orderPushApiService.handleOrderPush(orderPushRequestDTO);
            return Response.success();
        } catch (Exception e) {
            log.error("速回收推送网关处理失败: ", e);
            return Response.error("处理失败");
        }
    }
}
